package com.test.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
public class HelloController {
    @RequestMapping("/hello")
    public String hello(Model model){
        //封装数据
        model.addAttribute("msg","hello spring mvc");
        //admin/hello   文件夹下的文件
        return "hello"; //会被视图解析器处理,hello是页面的名称
    }

    //restful 风格使用
    @RequestMapping("/add/{a}/{b}")
    public String test1(@PathVariable int a,@PathVariable int b, Model model){
        int res = a + b;
        model.addAttribute("msg",res);
        //默认是转发
        return "hello";
    }

    //@RequestMapping(name="/add/{a}/{b}",method = RequestMethod.DELETE)  //限制请求类型
    //@GetMapping("/add/{a}/{b}")  //限制请求类型
    @DeleteMapping("/add/{a}/{b}")
    public String test2(@PathVariable int a,@PathVariable int b, Model model){
        int res = a + b;
        model.addAttribute("msg",res);
        return "hello";
    }
}
